package org.jsola.contract.service.impl;

import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import lombok.extern.slf4j.Slf4j;

/**
 * itext字体扩展，默认使用宋体
 *
 * @author JanusMix
 */
@Slf4j
public class AsianFontProvider extends XMLWorkerFontProvider {

    @Override
    public Font getFont(String fontName, String encoding, float size, int style) {
        try {
            BaseFont baseFont = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            return new Font(baseFont, size, style);
        } catch (Exception e) {
            log.error("未找到字体包");
            e.printStackTrace();
        }
        return super.getFont(fontName, encoding, size, style);
    }
}
